package com.config;

import com.common.ServiceException;
import com.pojo.dto.Message;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ErrorHandler {
    @ExceptionHandler(value = ServiceException.class)
    @ResponseBody
    public Message<String> handl(ServiceException e) {
        return Message.errorMessage(e.getCode(), e.getMsg());
    }

    @ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public Message<String> handl(RuntimeException e) {
        return Message.errorMessage("5000", e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Message<String> handl(Exception e) {
        return Message.errorMessage("6000", e.getMessage());
    }
}
